const { maskPhoneNumber } = require('../../../../utils/hooks');
const Toast = require('../../../../miniprogram_npm/@vant/weapp/toast/toast');
const $api = require('../../../../request/api').API;
Page({
  data: {
    loading: true,
    phoneShow: false,
    details: undefined
  },
  onLoad: function (options) {
    const { orderId } = options;
    this.fetchOrderDischarge(orderId);
  },
  /**
   * 获取转诊详情
   * @param orderId
   */
  fetchOrderDischarge(orderId) {
    $api
      .getOrderDischarge({ orderId })
      .then(res => {
        this.setData({
          details: {
            ...res.data.data,
            doctorPhone_show: res.data.data.doctorPhone,
            doctorPhone_hide: maskPhoneNumber(res.data.data.doctorPhone)
          },
          loading: false
        });
      })
      .catch(() => {
        this.setData({ loading: false });
      });
  },
  /**
   * 眼睛点击，切换电话显示隐藏
   */
  handleEyeClick() {
    this.setData({ phoneShow: !this.data.phoneShow });
  },

  /**
   * 点击医师️电话拨打
   */
  handlePhoneClick() {
    const { phoneShow, details } = this.data;
    if (phoneShow) {
      wx.makePhoneCall({
        phoneNumber: details.doctorPhone,
        fail: function () {
          console.log('拨打电话失败！');
        }
      });
    }
  }
});
